package jwebtester.utils;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.junit.Assert;

public class CollectionsAssert {
	public static <T> void assertEqualsByElement(List<T> lhs, List<T> rhs) {

		boolean areEqual = false;
		
		if (lhs == null && rhs == null)
			areEqual = true;
		else {
			if ((lhs == null && rhs != null) || (lhs != null && rhs == null)) {
				areEqual = false;
			} else {
				HashSet<T> lhsSet = new HashSet<T>(lhs);
				HashSet<T> rhsSet = new HashSet<T>(rhs);

				areEqual = lhsSet.equals(rhsSet);
			}
		}
		
		Assert.assertTrue(areEqual);
	}

	public static <T> void assertEqualsByElement(List<T> lhs, T... rhs) {
		
		boolean areEqual = false;

		if (lhs == null && rhs == null)
			areEqual = true;
		else {
			if ((lhs == null && rhs != null) || (lhs != null && rhs == null)) {
				areEqual = false;
			} else {
				Set<T> lhsSet = new HashSet<T>(lhs);
				Set<T> rhsSet = new HashSet<T>();
				
				for(int i = 0; i < rhs.length; ++i){
					rhsSet.add(rhs[i]);
				}

				areEqual = lhsSet.equals(rhsSet);
			}
		}
		
		Assert.assertTrue(areEqual);
	}
}
